package acm.蓝桥排序枚举杯;

import acm.第二轮.E;

import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class M {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        PriorityQueue<int[]>queue=new PriorityQueue<>((a,b)->{
            int i = (a[0] + a[1] + a[2]) - (b[0] + b[1] + b[2]);
            return i==0?a[2]-b[2]:i;    //如果总时长相等则比较发消息的时间
        });
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            int[] nums={sc.nextInt(),sc.nextInt(),sc.nextInt()};
            queue.add(nums);
        }
        long curr=0;
        long res=0;
        while (queue.size()>1){
            int[] nums = queue.poll();
            curr+=nums[0]+nums[1];
            res+=curr;
            curr+=nums[2];
        }
        int[] poll = queue.poll();
        curr+=poll[0]+poll[1];
        res+=curr;
        System.out.println(res);
    }
}
class Test{
    public static void main(String[] args) {
//        long fun = Answer.fun(1, new int[][]{{3, 8, 1}});
//        System.out.println(fun);
        compare();
    }

    public static void compare(){
        int count=10000;
        while (count-- > 0) {
            int n= (int) (Math.random()*200+1);
            int[][] arrs=new int[n][3];
            for (int[] arr : arrs) {
                arr[0]= (int) (Math.random()*9+1);
                arr[1]= (int) (Math.random()*9+1);
                arr[2]= (int) (Math.random()*3)+1;
            }
            long answer=0;
            long fun=0;
            try {
//                fun= M.fun(n, arrs);
//                answer=Answer.fun(n, arrs);
            }finally {
                if (answer!=fun){
                    System.out.println(n);
                    for (int[] arr : arrs) {
                        System.out.println(Arrays.toString(arr));
                    }
                    System.out.println("预期："+answer);
                    System.out.println("实际："+fun);
                }
            }
        }
    }
}